package com.longcai.piaojia.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.longcai.piaojia.BaseApplication;
import com.longcai.piaojia.R;
import com.longcai.piaojia.adapter.CouponListAdapter;
import com.longcai.piaojia.conn.MineCouponListGet;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/8/4.
 */
public class CouponUsedFragment extends BaseFragment {


    @BoundView(R.id.coupon_lv) private ListView coupon_lv;
    @BoundView(R.id.coupon_no_coupon_rl) private RelativeLayout coupon_no_coupon_rl;
    private List<MineCouponListGet.MineCouponEntity> lists = new ArrayList<>();
    private CouponListAdapter adapter;

    private MineCouponListGet mineCouponListGet = new MineCouponListGet(new AsyCallBack<MineCouponListGet.MineCouponListEntity>(){

        @Override
        public void onSuccess(String toast, int type, MineCouponListGet.MineCouponListEntity mineCouponListEntity) throws Exception {

            lists.addAll(mineCouponListEntity.mineCouponList);

            adapter.notifyDataSetChanged();

            if (lists.size() > 0) {

                coupon_no_coupon_rl.setVisibility(View.GONE);
                coupon_lv.setVisibility(View.VISIBLE);


            } else {

                coupon_no_coupon_rl.setVisibility(View.VISIBLE);
                coupon_lv.setVisibility(View.GONE);

            }

        }

        @Override
        public void onFail(String toast, int type) throws Exception {


        }
    });

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = BoundViewHelper.boundView(this, inflater.inflate(R.layout.fragment_coupon, null));

        mineCouponListGet.user_id = BaseApplication.BasePreferences.readUserId();
        mineCouponListGet.type = "2";
        mineCouponListGet.execute(getActivity());

        coupon_lv.setAdapter(adapter = new CouponListAdapter(getContext(), lists, 3));

        coupon_lv.setDivider(null);

        coupon_no_coupon_rl.setVisibility(View.GONE);

        return view;
    }


}
